package com.wechat.scheme.controller;

import com.wechat.scheme.entity.SchemeUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import javax.servlet.http.HttpServletRequest;


public class BaseCtrl {


 public String getAppId(HttpServletRequest request){
     return "testAppId";
 }

public SchemeUser getUser(){
    SecurityContext context = SecurityContextHolder.getContext();
    Authentication auth = context.getAuthentication();
    if (auth == null) return null;
    Object principal = auth.getPrincipal();
    if (principal instanceof SchemeUser) {
        return (SchemeUser) principal;
    } else {
        return null;
    }
}

}
